#ifndef TCP_SOCKET_CONNECTION_H_
#define TCP_SOCKET_CONNECTION_H_

#include "./../write_read_module/buffer.h"
#include "socket_address.h"
#include "socket_channel.h"
#include "socket_connection.h"

#include <atomic>
#include <memory>
#include <mutex>

class Loop;
class ChannelProtocol;
class Description;
class TcpSocketChannel;
class SocketChannel;
class TcpSocketConnection : public SocketConnection,
                            public std::enable_shared_from_this<TcpSocketConnection>
{
public:
    explicit TcpSocketConnection(Loop * loop);
    ~TcpSocketConnection() override;
    int  OpenSocket(SocketAddress address, Option option) override;
    int  AsyncConnect(SocketAddress address, Option option) override;
    int  AsyncWrite(const uint8_t * data, int data_size) override;
    int  AsyncRead() override;
    void Close() override;
    friend class TcpSocketChannel;
private:
    WriteBuffer m_read_buffer;
    WriteBuffer m_write_buffer;
private:
    Loop *                         m_loop;
    std::shared_ptr<SocketChannel> m_channel;
    std::shared_ptr<Description>   m_description;
    std::mutex                     m_mtx;
};

#endif
